package com.bluesky.objectworld.method.statement;

import com.bluesky.objectworld._Object;
import com.bluesky.objectworld.method.block.Block;
import com.bluesky.objectworld.method.reference.Reference;

public class MessageStatment {
	/**
	 * variables names
	 */

	public String responseVar;
	public Reference receiver;
	public String messageName;
	public Reference[] messageParameters;

	/**
	 * objects
	 */
	public _Object response;

	public MessageStatment(String responseVar, Reference receiver,
			String messageName, Reference... messageParameters) {
		this.responseVar = responseVar;
		this.receiver = receiver;
		this.messageName = messageName;
		this.messageParameters = messageParameters;
	}

	/**
	 * point variable to object.
	 * 
	 * @param block
	 */
	public void compile(Block block) {
		if (receiver != null) {
			receiver.compile(block);
		}

		if (messageParameters != null)
			for (Reference r : messageParameters) {
				if (r != null)
					r.compile(block);
			}
	}
	@Override
	public String toString() {
	
		StringBuilder sb = new StringBuilder();
		int i=0;
		for(Reference r: messageParameters){
			if(i>0)
				sb.append(",");
			
			sb.append( r.getLiteral());
			
			i++;
		}
		
		return String.format("%s=%s.%s(%s)", responseVar,receiver.getLiteral(),messageName,sb.toString());
	}

}
